
local isFast = false


local GameController = {}
function GameController:getInstance() end
function GameController:new()
   local gameController = {}
   gameController._instance, gameController.lastTime,gameController.callbacks = nil,nil,{}

   function gameController:enterFrame(event)
      assert(lastTime,"Previous time is null :(")
      local delta = (event.time - lastTime) / 1000.0
      lastTime = event.time

      if isFast then delta = delta * 10 end

      for i, callback in pairs(self.callbacks) do
         if callback ~= nil then
            self.callbacks[i](delta)
         end
      end
   end

   function gameController:addCallback(callback, name)
      self.callbacks[name] = callback
   end

   function gameController:clearAllCallbacks()
      self.callbacks = {}
   end

   function gameController:stop()
      Runtime:removeEventListener("enterFrame", self)
   end

   function gameController:beginGame()
      lastTime = system.getTimer()
      isFast = false
      Runtime:addEventListener("enterFrame", self)
   end

   return gameController
end

return GameController